package cn.com.winning.ecare.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.media.MediaPlayer;

public class Utils {

	public static Map<String, Object> getMap(String jsonString)

	{

		JSONObject jsonObject;

		try

		{

			jsonObject = new JSONObject(jsonString);
			@SuppressWarnings("unchecked")
			Iterator<String> keyIter = jsonObject.keys();

			String key;

			Object value;

			Map<String, Object> valueMap = new HashMap<String, Object>();

			while (keyIter.hasNext())

			{

				key = (String) keyIter.next();

				value = jsonObject.get(key);

				valueMap.put(key, value);

			}

			return valueMap;

		}

		catch (JSONException e)

		{

			e.printStackTrace();

		}

		return null;

	}

	public static void playSound(Context context, int soundreouse) {
		MediaPlayer mp = MediaPlayer.create(context, soundreouse);
		mp.start();
	}
	
	public static String sqliteEscape(String keyWord){
	    keyWord = keyWord.replace("/", "//");
	    keyWord = keyWord.replace("'", "''");
	   // keyWord = keyWord.replace("[", "/[");
	   // keyWord = keyWord.replace("]", "/]");
	    keyWord = keyWord.replace("%", "/%");
	    keyWord = keyWord.replace("&","/&");
	    keyWord = keyWord.replace("_", "/_");
	    keyWord = keyWord.replace("(", "/(");
	    keyWord = keyWord.replace(")", "/)");
	    return keyWord;
	}



}
